import { useReducer, useRef, useState } from "react";
import { Tracker } from '../reactive';

export function Observer(props) {
  //先定义一个可以让组件强行刷新的方法
  //const [, forceUpdate] = useReducer(x => x + 1, 0);
  const [, forceUpdate] = useState({});
  //创建一跟踪顺口的ref
  const trackerRef = useRef(null);
  if (!trackerRef.current) {
    //创建一个手动的跟踪器
    trackerRef.current = new Tracker(() => forceUpdate({}));
  }
  return trackerRef.current.track(props.children);
}